package com.slimbloody.score;

import com.slimbloody.score.interfaces.MatchContextSupplier;
import com.slimbloody.score.interfaces.Rule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Component
public class StrategyExecutor {
  @Autowired
  private Map<String, Rule> ruleMap;

  public List<Rule> getMatchedRules(Map<String, MatchContextSupplier> matchContextSupplierMap) {
    List<Rule> calRuleList = new ArrayList<>();
    for (Map.Entry<String, Rule> entry: ruleMap.entrySet()) {
      MatchContextSupplier matchContextSupplier = matchContextSupplierMap.get(entry.getKey());
      Rule rule = entry.getValue();

      if (Objects.isNull(matchContextSupplier)) {
        continue;
      }

      boolean match = rule.match(matchContextSupplier);
      if (match) {
        calRuleList.add(rule);
      }
    }

    return calRuleList;
  }

  /*
  public List<Map<Integer, Score>> execute(Map<String, > matchContextSupplierMap) {
    List<Rule> calRuleList = new ArrayList<>();
    for (Map.Entry<String, Rule> entry: ruleMap.entrySet()) {
      MatchContextSupplier matchContextSupplier = matchContextSupplierMap.get(entry.getKey());
      Rule rule = entry.getValue();

      if (Objects.isNull(matchContextSupplier)) {
        continue;
      }

      boolean match = rule.match(matchContextSupplier);
      if (match) {
        calRuleList.add(rule);
      }
    }

    return calRuleList;
  }
   */
}
